using System;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class LevelCreate : MonoBehaviour
	{
		public Text scoreText;

		public Transform[] Enemys;

		public Transform[] stunts;

		public Transform PaneFactory()
		{
			int num = UnityEngine.Random.Range(0, 4);
			if (num < 3)
			{
				return null;
			}
			return PaneManage();
		}

		private Transform PaneManage()
		{
			int num = UnityEngine.Random.Range(0, 3);
			if (num < 2)
			{
				return CreateEnemy();
			}
			return CreateStunt();
		}

		public Transform CreateStunt()
		{
			int num = UnityEngine.Random.Range(0, stunts.Length);
			return UnityEngine.Object.Instantiate(stunts[num]);
		}

		public Transform CreateEnemy()
		{
			int num = UnityEngine.Random.Range(0, Enemys.Length);
			Transform transform = UnityEngine.Object.Instantiate(Enemys[num]);
			transform.GetComponent<Renderer>().material.color = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
			transform.rotation = Quaternion.Euler(0f, 0f, UnityEngine.Random.Range(0, 90));
			Transform transform2 = transform.GetComponentInChildren<Text>().transform;
			transform2.rotation = Quaternion.Euler(0f, 0f, 0f);
			int num2 = Convert.ToInt32(scoreText.text);
			if (num2 < 100)
			{
				transform.GetComponentInChildren<Text>().text = UnityEngine.Random.Range(1, 10).ToString();
			}
			else
			{
				transform.GetComponentInChildren<Text>().text = UnityEngine.Random.Range(1, num2 / 10).ToString();
			}
			return transform;
		}
	}
}

